package mchecca;

import java.util.Scanner;

import mchecca.model.DecisionLinesEvent;
import mchecca.view.DecisionLinesForm;

/**
 * Main class for launching DecisionLines.
 * 
 * Contains the sacred {@code public static void main} entry point.
 * @author Michael Checca
 */
public class Main {

	/**
	 * Create the GUI and launch DecisionLines
	 * @param args Command line arguments to DecisionLines (currently ignored)
	 */
	public static void main(String[] args) {
		int numRounds = 0;
		int numChoices = 0;
		Scanner keyboard = new Scanner(System.in);
		while (!validInput(numRounds)) {
			System.out.print("Number of rounds (M): ");
			try {
				numRounds = Integer.parseInt(keyboard.nextLine());
			} catch (NumberFormatException nfe) {
				System.err.println("Cannot be parsed as a number");
			}
		}
		while (!validInput(numChoices)) {
			System.out.print("Number of lines (N): ");
			try {
				numChoices = Integer.parseInt(keyboard.nextLine());
			} catch (NumberFormatException nfe) {
				System.err.println(String.format("%s cannot be parsed as a number", numChoices));
			}
		}
		DecisionLinesForm dlForm = new DecisionLinesForm(
				new DecisionLinesEvent(numChoices, numRounds));
		dlForm.setVisible(true);
	}

	/**
	 * Determines if the number of choices/rounds is valid.
	 * 
	 * Valid values for number of choices and number of rounds is between 3 and 8.
	 * @param number Number to validate
	 * @return Returns true if 3 <= number <= 8
	 */
	private static boolean validInput(int number) {
		return number >= 3 && number <= 8;
	}
}
